package bigbank.web;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import bigbank.BankService;

@Controller
public class ListAccounts {

    @Autowired
    private BankService bankService;

//    public ListAccounts(BankService bankService) {
//        this.bankService = bankService;
//    }

    @RequestMapping("/listAccounts.html")
    @PreAuthorize("isAuthenticated()")
    public String handleRequest(ModelMap model) throws Exception {
        // Security check (this is unnecessary if Spring Security is performing the authorization)
//        if (request.getUserPrincipal() == null) {
//            throw new AuthenticationCredentialsNotFoundException("You must login to view the account list (Spring Security message)"); // only for Spring Security managed authentication
//        }

//    	if (user != null) {
//    		System.out.println(user.getUsername());
//    	}
    	
        model.addAttribute("accounts", bankService.findAccounts());
        return "listAccounts";
    }

}
